﻿#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
struct info_person
{
	char name[21];
	int age;
	char sex;
	double weight;
	bool hello;
};
void func(const info_person* p)
{
	cout << "-----------------------------------------------------------------------"<<endl;
	cout << "姓名：" << p->name << "、年龄：" << p->age << "、性别：" << p->sex
		<< "、体重：" << p->weight << "、咋样：" << p->hello << endl;
	//strcpy(p->name, "大壮");//C风格字符串，不能用等号直接赋值。加上const之后不能修改实参
	//p->age = 18;
}
int main()
{
	info_person person{ "三毛" ,30,'X',77.8,false };
	cout << "姓名：" << person.name << "、年龄：" << person.age << "、性别：" << person.sex
		<< "、体重：" << person.weight << "、咋样：" << person.hello << endl;
	info_person* p = &person;
	//访问成员变量：两种方法
	//方法1,对指针解引用
	cout << "姓名：" << (*p).name << "、年龄：" << (*p).age << "、性别：" << (*p).sex
		<< "、体重：" << (*p).weight << "、咋样：" << (*p).hello << endl;
	//方法2，->运算符
	cout << "姓名：" << p->name << "、年龄：" << p->age << "、性别：" << p->sex
		<< "、体重：" << p->weight << "、咋样：" << p->hello << endl;
	func(&person);
	cout << "修改了变量的值" << endl;
	cout << "姓名：" << p->name << "、年龄：" << p->age << "、性别：" << p->sex
		<< "、体重：" << p->weight << "、咋样：" << p->hello << endl;

	//动态分配内存
	info_person* pp = new info_person({0});//初始清空
	//memset(pp, 0, sizeof(info_person));//sizeof不能使用指针，使用指针永远是8
	cout << "姓名：" << pp->name << "、年龄：" << pp->age << "、性别：" << pp->sex
		<< "、体重：" << pp->weight << "、咋样：" << pp->hello << endl;
	delete pp;//手动清除
}

